package com.czh.gzskzn.shenke3.Activity.ShuiFeiActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.czh.gzskzn.shenke3.Activity.UtilServer.WanZhi;
import com.czh.gzskzn.shenke3.R;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by gzsk on 2017/5/2.
 * name  陈忠红
 * email czhhx15599109256@163.com
 */
public class ShuiFeiJiaonaActivity extends AppCompatActivity {


    private LinearLayout back;
    private EditText shuRuChaXun;
    private Button shuiFeiXQ;
    private TextView xiYe,shuiWuWeiZhi;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_water_rate_login);
//        实例化控件
        intiView();
//     点击事件处理
        dianJiShiJian();

    }

    private void dianJiShiJian() {


        shuiFeiXQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final String abc = shuRuChaXun.getText().toString().trim();
                OkGo.get(WanZhi.SHUIFEICHAXUN+abc)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(String s, Call call, Response response) {
                                try {
                                    JSONObject jsonod = new JSONObject(s);
//                                    String msg = jsonod.getString("msg");
                                    String success = jsonod.getString("success");
                                    if (success.equals("true")){
                                        Intent intent = new Intent(ShuiFeiJiaonaActivity.this,ShuiFeiXQ.class);
                                        //用Bundle携带数据
                                        Bundle bundle=new Bundle();
                                        //传递name参数为tinyphp
                                        bundle.putString("hao",abc);
                                        intent.putExtras(bundle);
                                        startActivity(intent);
                                    }else {

                                        Toast.makeText(ShuiFeiJiaonaActivity.this, "没有此用户", Toast.LENGTH_SHORT).show();
                                    }

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }
                        });
            }
        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        xiYe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ShuiFeiJiaonaActivity.this,SxyActivity.class);
                startActivity(intent);
            }
        });

    }

    private void intiView() {
        shuRuChaXun = (EditText) findViewById(R.id.et_bianhao);
        shuiFeiXQ = (Button) findViewById(R.id.btn_waterXQ);
        xiYe = (TextView) findViewById(R.id.tv_xiye);
        shuiWuWeiZhi = (TextView) findViewById(R.id.tv_gonsi);

        back = (LinearLayout) findViewById(R.id.water_imag);
    }
}
